package com.framework.admin.controller;

import com.framework.admin.domain.param.SysCompanyFormParam;
import com.framework.admin.domain.param.SysCompanyParam;
import com.framework.admin.service.ISysCompanyService;
import com.framework.common.domain.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * @description: 公司表 Service
 * @author: lusy
 * @version: 1.0
 * @date: 2021-03-05 10:59:15
 */
@RestController
@RequestMapping("/syscompany")
@Api(value = "SysCompany", tags = "公司表")
public class SysCompanyController {
    @Autowired
    private ISysCompanyService baseService;
    
    @ResponseBody
    @ApiOperation(value = "新增")
    @PostMapping(value = "/add")
    public ResultData<?> add(@RequestBody @Valid SysCompanyFormParam param) {
        return ResultData.success(baseService.save(param));
    }

    @ResponseBody
    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public ResultData<?> delete(@RequestBody List<String> ids) {
        baseService.delete(ids);
        return ResultData.success();
    }

    @ResponseBody
    @ApiOperation(value = "编辑")
    @PostMapping(value = "/edit")
    public ResultData<?> edit(@RequestBody @Valid SysCompanyFormParam param) {
        baseService.update(param);
        return ResultData.success();
    }
    @ApiOperation("获取分页")
    @PostMapping(value = "/listPage")
    public ResultData<?> listPage(@RequestBody(required = false) SysCompanyParam param) {
        PageRequest pageRequest = PageRequest.of(param.getPageNo(), param.getPageSize());
        return ResultData.data(baseService.listPage(param, pageRequest));
    }
}
